﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Base
@using ZBJF.Warranty.Common.Enums.InsuranceProducts
@{
    ViewBag.Title = "保险卡列表";
    var seller = ServiceFactory.SellersServiceInstance.LoadByID(CurrentLoginUser.CurrentUser.SellerId);
    var iSPSalingType = seller.SaleSystemType == (byte)SaleSystemTypeEnums.ISPSalingType;
    var shareUrl = "http://" + Request.Url.Authority + "/InsuranceProduct/ValidateIMEI?SellerId=" + CurrentLoginUser.CurrentUser.SellerId + "&SellerEmployeeID=" + CurrentLoginUser.CurrentUser.ID;
}
<link href="~/Content/layout.css" rel="stylesheet" />

<div class="user-center-header">
    <div class="header_container">
        <div class="logo" onclick="location.href = '/SellerEmpoyee/Setting'"></div>
        <div class="detail">
            <div class="title">
                <span class="name">@CurrentLoginUser.CurrentUser.UserName</span>
                <span class="phone">@CurrentLoginUser.CurrentUser.UserPhone</span>
            </div>
            <div class="bar">
                <div class="bar_list">
                    @CurrentLoginUser.CurrentUser.InsuranceCompany
                </div>
                <span class="space-point">
                    .
                </span>
                <div class="bar_list">
                    @CurrentLoginUser.CurrentUser.InsuranceCompanyBranch
                </div>
                <span class="space-point">
                    .
                </span>
                <div class="bar_list">
                    @CurrentLoginUser.CurrentUser.Sellers.SellersName
                </div>
            </div>
        </div>
    </div>
</div>
@if (iSPSalingType)
{
    <div id="tab1" class="weui-tab__bd-item">
        <div class="align-center">
            <div id="qrcode" class="qrcode" onclick="createQrCode()"></div>
        </div>
        <div class="weui-loadmore weui-loadmore_line weui-loadmore_dot">
            <span class="weui-loadmore__tips">扫码购买</span>
        </div>
    </div>
    <script src="~/Scripts/qrcode.js"></script>
    <script type="text/javascript">
        var qrcode;
        var _url = '@(shareUrl)'.replace(/&amp;/g, "&") + "&t=" + new Date().getTime();
        $(function () {
            var qrcodeDiv = $("#qrcode").html();
            if (qrcodeDiv == undefined) return;
            qrcode = new QRCode('qrcode', {
                text: _url,
                width: 256,
                height: 256,
                colorDark: '#000000',
                colorLight: '#ffffff',
                correctLevel: QRCode.CorrectLevel.H
            });
        });
        function createQrCode() {
            qrcode.clear();
            qrcode.makeCode('@(HttpUtility.HtmlDecode(shareUrl))'.replace(/&amp;/g, "&") + "&t=" + new Date().getTime());
        }
    </script>
}
else
{
    <div class="zbjf-product-general">
        <div class="online">
            <p id="totalSaleProduct">0</p>
            <span>在售产品</span>
        </div>
        <div class="onsale" onclick="location.href = '/InsuranceProductOrder/Index'">
            <p>@ServiceFactory.InsuranceProductOrderCardServiceInstance.GetInsuranceCardCount(0, 0, employeeId: CurrentLoginUser.CurrentUser.ID)</p>
            <span>已售产品</span>
        </div>
        <div class="activated" onclick="location.href = '/InsuranceProductOrderCard/Index?Status=@((byte) InsuranceProductOrderCardStatus.Activated)'">
            <p>@ServiceFactory.InsuranceProductOrderCardServiceInstance.GetInsuranceCardCount(0, 0, employeeId: CurrentLoginUser.CurrentUser.ID, status: InsuranceProductOrderCardStatus.Activated)</p>
            <span>已激活卡片</span>
        </div>
    </div>
    <div class="space-8"></div>
    <div id="productList" class="zbjf-product-list">

    </div>
    <div class="weui-loadmore" style="display: none">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">上拉加载更多数据</span>
    </div>
    <div class="zbjf-product-nomore" style="display: none">
        <div class="left">
            <hr>
        </div>
        <div class="center-text">没有更多数据了</div>
        <div class="right">
            <hr>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            var iDisplayLength = parseInt((document.documentElement.clientHeight) / 150);
            var currentPageIndex = 0;
            var loading = false; //状态标记
            $(document.body).infinite(111).on("infinite", function () {
                if (loading) return;
                loading = true;
                $.ajax({
                    url: "/InsuranceProduct/GetProductCard?ProductAmount=@(Request["ProductAmount"])",
                    type: "post",
                    data: { iDisplayStart: currentPageIndex * iDisplayLength, iDisplayLength: iDisplayLength },
                    success: function (result) {
                        loading = false;
                        currentPageIndex++;
                        var html = "";
                        if (result && result.sellerInsuranceProductsList && result.sellerInsuranceProductsList.length > 0) {
                            for (var i = 0; i < result.sellerInsuranceProductsList.length; i++) {
                                var item = result.sellerInsuranceProductsList[i];
                                html += "<a href='/InsuranceProduct/BuyProduct/" + item.ID + "'>";
                                html += '<div class="product-item">';
                                html += '<img class="product-list-imgage" src="' + item.FirstImagePath + '"/>';
                                html += '<div class="zbjf-product-content"><div class="title">';
                                html += item.ProductName + '</div>';
                                html += "<div class='weui-media-box__desc'>" + item.Tags + "</div>";
                                html += '<div class="sale-condition"><div class="price">';
                                html += "¥<span class='money'>" + item.SaleRetailPrice + "</span></div>";
                                html += '<div class="saleNum">销量';
                                html += item.SellerInsuranceProductSaleCount + '份</div>';
                                html += "</div></div></div></div></a>";
                            }
                        }
                        $('#productList').append(html);
                        if (result.isLastPage) {
                            $(document.body).destroyInfinite();
                            $('.weui-loadmore').hide();
                            $('.zbjf-product-nomore').show();
                        } else {
                            if (currentPageIndex >= 1)
                                $('.weui-loadmore').show();
                        }
                        $("#totalSaleProduct").text(result.total);
                    }
                });
            });
            $(document.body).trigger("infinite");
        })
    </script>
}
